<?php
/**
 * Created by PhpStorm.
 * Date: 2018/9/26
 * Time: 下午6:47
 */?>
<?php //if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class c_login extends CI_Controller
{

    function __construct()
    {
        parent::__construct();
        $this->load->library('session');
    }

    function index()
    {
        $data = array();
        //	$this->load->view('Copy/js');
        $this->load->view('v_login',$data);
    }

    //----------------------------------------------------------------------------------------------------
    /**
     * 登陆检验
     *
     *
     */
    function signin()
    {
        if($this->input->post('act') == 'signin')
        {
            //接受客户端数据
            $name = $this->input->post('admin_name');
            $password = $this->input->post('admin_password');

//            echo $name;
//            echo $_POST['name']."<br/>";
//            echo $password."<br/>";

            //把数据提交给模型
            $this->load->model('m_admin_user');
            $this->m_admin_user->ID = $name;
            $this->m_admin_user->password = $password;
//            $data['name'] = $name;
//            $data['password'] = $password;
//            echo $name;
//            echo $password;
            $user2=$this->m_admin_user->signin();
            $user=1;
            if( $user = $user2)
            {
//                echo $name;
//                $data['name']=$name;
                redirect('c_front_bacteria');

            }
            //用户名和密码不匹配
            else
            {
                //echo 2;
//                $data['name']=$name;
                //show_message2('用户名或者密码错误！','login');
                //redirect('c_login');
//                echo "用户名或者密码错误，或管理员身份过期！";
                $this->load->view('bacteria/v_admin_fail');
            }
        }
        //非法登陆
//        else
//        {
//            redirect('c_login');
//            echo "86";
//        }

    }
    function manage(){
        if($_POST) {
            $_SESSION['user_id'] = $_POST["session_user_id"];
            $_SESSION['user_name'] = $_POST["session_user_name"];
            $_SESSION['role_id'] = $_POST["session_role_id"];
            $_SESSION['logged_in'] = $_POST["session_logged_in"];
            //print_r($_POST);
            //print_r(@$_SESSION['logged_in']);

        }

        //print_r($_POST['session']);
        if (@$_SESSION["logged_in"]==0)      //=============================================!!!!!!!!!!!!!!!!!!!!!!!
        {
            //print_r($_SESSION);
            redirect('c_login');

            exit();
        }
        $this->load->view('_frameset');
    }

    //----------------------------------------------------------------------------------------------
    /**
     * 注销
     *
     *
     */
    function logout()
    {
        $this->session->sess_destroy();
        //redirect('c_login');
        //print_r($_SESSION);
        $this->load->view('welcome_message');
    }
}
?>
